//
//  YKDataPageViewController.m
//  YunKang
//
//  Created by leoking870 on 2017/10/26.
//  Copyright © 2017年 leoking870. All rights reserved.
//

#import "YKDataPageViewController.h"
#import "YKDataViewController.h"
#import "YKDataSaleViewController.h"
#import "YKStorageDataViewController.h"
#import "YKDataPersonViewController.h"
#import <TFSegmentConfigModel.h>

@interface YKDataPageViewController ()

@property(nonatomic, strong) UIBarButtonItem *filterItem;
@end

@implementation YKDataPageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.segmentView.backgroundColor = [UIColor tf_colorWithHexString:@"#d6f3ff"];
    self.navigationItem.title = @"统计管理";
    
    
    UIBarButtonItem *refreshItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"icon_refresh"] style:UIBarButtonItemStyleDone target:self action:@selector(onRefreshItemTapped:)];
    self.navigationItem.rightBarButtonItem = refreshItem;

    self.filterItem = [[UIBarButtonItem alloc] initWithTitle:@"筛选" style:UIBarButtonItemStylePlain target:self action:@selector(onFilterItemTapped:)];
}

- (void)onRefreshItemTapped:(id)sender {
    id<RefreshDelegate> delegate = [self currentViewController];
    [delegate loadData];
}

- (NSArray *)titlesForViewControllers {
    return @[@"按区域",@"按品种",@"按人员",@"查库存"];
}

- (void)didScrollToIndex:(NSUInteger)index {
    if (index == 3) {
        self.navigationItem.rightBarButtonItem = self.filterItem;
    } else{
        UIBarButtonItem *refreshItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"icon_refresh"] style:UIBarButtonItemStyleDone target:self action:@selector(onRefreshItemTapped:)];
        self.navigationItem.rightBarButtonItem = refreshItem;
    }
}

- (void)onFilterItemTapped:(id)onFilterItemTapped {
    UIViewController *controller = [self currentViewController];
    [controller performSelector:@selector(onFilterItemTapped:) withObject:onFilterItemTapped];
}

- (UIViewController *)viewControllerAtIndex:(NSUInteger)index {
    if (index == 0) {
        YKDataViewController *vc = [[YKDataViewController alloc] init];
        return vc;
    }
    else if(index == 1){
        YKDataSaleViewController *vc = [[YKDataSaleViewController alloc]init];
        return vc;
    }
    else if (index == 2){
        YKDataPersonViewController *vc = [[YKDataPersonViewController alloc]init];
        return vc;
    }
    else {
        YKStorageDataViewController *vc = [YKStorageDataViewController new];
        return vc;
    }
}

- (TFSegmentConfigModel *)segmentConfigModel {
    TFSegmentConfigModel* model = [[TFSegmentConfigModel  alloc]init];
    model.textColor = [UIColor tf_colorWithHexString:@"#040404"];
    model.selectedTextColor = TFSTYLE(buttonEnableBackgroundColor);
    model.lineColor = TFSTYLE(buttonEnableBackgroundColor);
    model.lineInsets = UIEdgeInsetsMake(42, 0, 0, 0);
    model.fillSegmentWithItemsWhenLessCount = YES;
    return model;
}

@end
